#ifndef SERVICE_PROTOCOL
#define SERVICE_PROTOCOL

//service data size
enum
{
    SIZE_ROBOTARM_SERVICE_HEADER_COMMAND = 28,
    SIZE_OF_ROBOTARM_SERVICE_MAX         = 300,
    SIZE_OF_PROGRAM_NAME_MAX             = 100,
};


//service cmd
enum ServiceCommand
{
    CMD_EMERGENCY_STOP 			= 1,
    CMD_SET_SERVO 				= 2,
    CMD_SET_BRAKE 				= 3,
    CMD_STOP 					= 4,
    CMD_MOVE_HOME				= 5,
    CMD_MOVE_ZERO				= 6,
    CMD_JOINT_MOVE_TO			= 7,
    CMD_JOINT_MOVE_BY			= 8,
    CMD_TASK_MOVE_TO			= 9,
    CMD_TASK_MOVE_BY			= 10,


    CMD_IS_ROBOT_RUNNING        = 40,
    CMD_IS_MOVE_FINISEHD        = 41,
    CMD_IS_HOME                 = 42,

    CMD_GET_JOINT_POSITION		= 320,
    CMD_GET_JOINT_VELOCITY		= 321,
    CMD_GET_CART_POSITION		= 322,
    CMD_GET_CART_VELOCITY		= 323,
    CMD_GET_TORQUE				= 324,

    CMD_PROGRAM_NEW             = 401,
    CMD_PROGRAM_OPEN            = 402,
    CMD_PROGRAM_SAVE            = 403,
    CMD_PROGRAM_SAVE_EXIT       = 404,
    CMD_PROGRAM_EXIT            = 405,
    CMD_PROGRAM_DELETE          = 406,
    CMD_PROGRAM_RUN             = 407,
    CMD_PROGRAM_STOP            = 408,

    CMD_WAYPOINT_PUSHBACK       = 421,
    CMD_WAYPOINT_INSERT         = 422,
    CMD_WAYPOINT_ERASE          = 423,
    CMD_WAYPOINT_REPLACE        = 424,
    CMD_WAYPOINT_CLEAR          = 425,
    CMD_WAYPOINT_UPDATE         = 426,


};


enum ErrorCode
{
    ERR_NONE = 0,
    ERR_NO_MATCHED_ROBOT = 1,
    ERR_NO_MATCHED_STEP = 2,
    ERR_HEADER_FORMAT = 4,
    ERR_OVER_DATA_SIZE = 5,
    ERR_NOT_SUPPORT_COMMAND = 6,
    ERR_UNKNOWN_COMMAND = 7,
    ERR_UNKNOWN_DATA = 8,
    ERR_PROCESS_FAILED = 9,
    ERR_PARSE_FAILED = 10,
    ERR_NO_MATCHED_PARAMETER = 11,
    ERR_NO_MATCHED_DATA_SIZE = 12,
    ERR_WRONG_ASCII_FORMAT = 13,
    ERR_ROBOT_MOVING_STATE = 14,
    ERR_ROBOT_PROGRAM_RUNNING = 15,
    ERR_ROBOT_MOVE_FAILED = 16,
    ERR_NO_DEFAULT_PROGRAM = 17,
    ERR_NO_CURRENT_PROGRAM = 18,
    ERR_CURRENT_PROGRAM_STATE = 19,
    ERR_EMG_STATE = 20,
    ERR_ROBOT_STATE = 21,
    ERR_ROBOT_PROGRAM_LOAD_FAILED = 22,
    ERR_DIRECT_VARIABLE_INVALID_ADDRESS = 23,
    ERR_DIRECT_VARIABLE_INVALID_FORMAT = 24,
    ERR_DIRECT_VARIABLE_REFNUM_LIMIT = 25,
    ERR_CONNECTION_EXCEPTION = 600,
    ERR_CONNECTION_TIMEOUT = 601,
};

typedef struct {
    unsigned int wayPointPointType;
    unsigned int wayPointMotionType;
    unsigned int wayPointIndex;
    double point[6];
}__attribute__((packed))ServiceWaypointType;

#define SIZE_OF_SERVICE_WAYPOINTTYPE sizeof(ServiceWaypointType)


//service header struct
struct robotarmServiceHeaderStruct // --> size 28
{
    char robotName[20];
    int  cmdId;
    int  dataSize;
}__attribute__((packed));


//service header union
union robotarmServiceHeader
{
    unsigned char byte[SIZE_OF_ROBOTARM_SERVICE_MAX];
    robotarmServiceHeaderStruct val;
}__attribute__((packed));


//service data union
union robotarmServiceData
{
    unsigned char byte[SIZE_OF_ROBOTARM_SERVICE_MAX];
    bool   boolval;
    char   charval;
    int    intval;
    double robotarmDeg[6];
    double robotarmCart[6]; // -->x, y, z, rx, ry, rz(m, rad)
    double robotarmVel[6];
    double robotarmCurrent[6];
    char programName[SIZE_OF_PROGRAM_NAME_MAX];
    ServiceWaypointType serviceWaypoint;
}__attribute__((packed));


//Service data type.
typedef enum
{
    SERVICE_DATATYPE_BOOL,
    SERVICE_DATATYPE_CHAR,
    SERVICE_DATATYPE_INT,
    SERVICE_DATATYPE_DEG6,
    SERVICE_DATATYPE_CART6,
    SERVICE_DATATYPE_CHARNAME,
    SERVICE_DATATYPE_WAYPOINT,
    SERVICE_DATATYPE_COUNT
}ServiceDataType;




#endif // SERVICE_PROTOCOL
